package ch08;

import java.util.Random;

public class RandomMain {
    public static void main(String[] args) {
        System.out.println(Math.random()); //[0,1)
        System.out.println((int)(Math.random()*(100-1+1)+1));

        Random random = new Random(System.currentTimeMillis());
        for (int i=1;i<=5;i++){
            System.out.println(random.nextInt(100-1+1)+1);
        }

        int [] arr = {11,22,33,44,55,66};
        for (int i=1;i<=3;i++){
//            System.out.println(arr[random.nextInt(arr.length)]);
            System.out.println(arr[Math.abs(random.nextInt()) % arr.length]);
        }

        String str = "0123456789ABCDEFGabcdefg";// 字库
        char[] c = str.toCharArray();
        StringBuffer sb = new StringBuffer();
        for(int i=1;i<=4;i++){
            sb.append(c[random.nextInt(c.length)]);
        }
        System.out.println("随机验证码: "+sb.toString());
    }
}
